<template>
	<view class="content">
		<view class="top">
			您的可用积分：
			<text>{{point}}</text>
		</view>
		<view class="img">
			<image :src="this.initData.image" mode="aspectFit"></image>
		</view>
		<view class="divider"></view>
		<view class="detail">
			<view class="names">
				{{this.initData.goodsName}}
				<view class="right">
					<text>剩余积分</text>{{point}}
				</view>
			</view>
			<view class="market">市价 {{this.initData.price}}</view>
			<view class="jifen">
				<view class="left">
					<text>{{this.initData.pointAmount}}</text>积分 <image src="../../../static/img/duihuan.png" mode=""></image>
				</view>
				<view class="control">
					<text @click="reduce">-</text>
					<text>{{num}}</text>
					<text @click="add">+</text>
				</view>
			</view>
		</view>
		<view class="divider"></view>
		<view class="title">商品描述</view>
		<view class="text">
			<rich-text :nodes="this.initData.description"></rich-text> 
		</view>
		<view class="btn">
			<view class="button" @click="submit">立即兑换</view>
		</view>
	</view>
</template>

<script>
	import integral from '../../../servers/integral/integral.js';
	export default {
		data() {
			return {
				initData:'',
				point:'',
				num:1,
				usepoint:''
			}
		},
		onLoad(option) {
			if(option.detail){
				this.initData=JSON.parse(option.detail) 
				this.usepoint=this.num*this.initData.pointAmount
			}
			this.point=option.point
			console.log(this.initData,this.point)	
		},
		methods: {
			add(){
				if(this.point>this.initData.pointAmount){
					this.num++;
					this.point=this.point-this.num*this.initData.pointAmount
					this.usepoint=this.num*this.initData.pointAmount
				}else{
					uni.showToast({
						title:'您现有积分不能兑换该商品',
						icon:'none'
					})
				}
				
			},
			reduce(){
				if(this.num!==1){
					
					this.point=this.point+this.num*this.initData.pointAmount					
					this.num--;
					this.usepoint=this.num*this.initData.pointAmount
				}else{
					uni.showToast({
						title:'不能在减拉……',
						icon:'none'
					})
				}
			},
			submit(){
				if(this.num&&this.point<this.initData.pointAmount){
					uni.showToast({
						title:'您现有积分不能兑换该商品',
						icon:'none'
					})
					return;
				}
				var obj={
					num:this.num,
					goodsPointId:this.initData.id,
					detail:JSON.stringify(this.initData),
					usepoint:this.usepoint
				}
				uni.navigateTo({
					url:'./particulars?detail='+JSON.stringify(obj)
					// url:'./particulars?num='+this.num+'&goodsPointId='+this.initData.id+'&detail='+JSON.stringify(this.initData)
				})
			}
		}
	}
</script>

<style scoped lang="scss" rel="stylesheet/scss">
	.top {	
		font-size: 28rpx;
		background: #ffffff;
		padding: 0 20rpx;
		box-sizing: border-box;
		line-height: 89rpx;
		box-shadow: 5rpx 0px 20rpx #c5c5c5;
		color: #666;
		text {
			font-size: 34rpx;
			color: #f70225;
		}
	}
	.img{
		border:1px solid #e1e1e1;
		height: 655rpx;
		margin: 50rpx 20rpx 40rpx;
		padding: 20rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.divider{
		height: 26rpx;
		background-color: #f6f6f6;
	}
	.detail{
		padding: 0 20rpx;
		.names{
			font-size: 28rpx;
			color: #000;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx 0;
			border-bottom: 1px solid #e1e1e1;
			.right{
				color: #333;
				text{
					color: #999;
					margin-right: 20rpx;
				}
			}
		}
		.market{
			font-size: 28rpx;
			color: #999;
			margin: 30rpx 0 0;
		}
		.jifen{
			font-size: 28rpx;
			color: #999;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 30rpx;
			.left{
				text{
					font-size: 34rpx;
					color: #f70225;
					margin-right: 10rpx;
				}
				image{
					width: 30rpx;
					height: 30rpx;
					margin-left: 10rpx;
					vertical-align: sub;
				}
			}
			
			.control {
				width: 200rpx;
				border: 1px solid #a0a0a0;
				/*no*/
				color: #333;
				display: flex;
				text-align: center;
				line-height: 58rpx;
				border-radius: 30rpx;
				font-size: 32rpx;
			
				text {
					flex: 1;
				}
			
				text:nth-child(2) {
					color: #f70225;
					border-left: 1rpx solid #9b9b9b;
					border-right: 1rpx solid #9b9b9b;
				}
			}
		}
		
	}
	.title{
		font-size: 30rpx;
		color: #000;
		border-bottom: 1px solid #e1e1e1;
		padding: 30rpx 0 20rpx;
		margin: 0 20rpx;
	}
	.text{
		padding: 20rpx;
	}
	.btn{
		padding: 40rpx 20rpx;
		.button {
			line-height: 90rpx;
			background: linear-gradient(80deg, #d2158a, #fc6395);
			text-align: center;
			color: #fff;
			border-radius: 45rpx;
			font-size: 32rpx;
			box-shadow: 3rpx 0 20rpx rgba(206, 205, 204, 0.35);
			
		}
	}
	
</style>
